<?php

namespace Admin\Controller;

class ClubfootController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Clubfoot");
    }

    //首页
    public function index() {

        $requestMap = $this->convertRequestToMap();

        //分页
        $count = $this->currentModel->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取列表
        $list = $this->currentModel->queryForList($page, $requestMap);

//        $this->assign("statusEnum", C("DEFAULT_YN"));
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin', $this->parameter));
        $this->display();

    }

    public function faq() {
        $requestMap = $this->convertRequestToMap();

        //分页
        $count = D("Faq")->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取列表
        $list = D("Faq")->queryForList($page, $requestMap);

//        $this->assign("statusEnum", C("DEFAULT_YN"));
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin', $this->parameter));
        $this->display();

    }

    public function faqAdd() {
        $productId = $_REQUEST["id"];
        $this->assign("productId", $productId);
        $this->display("faqadd");
    }

    public function faqAddPost() {

        $data["name"] = $_REQUEST["name"];
        $data["faq_class_id"] = $_REQUEST["faqClassId"];
        $data["question"] = $_REQUEST["question"];
        $data["answer"] = $_REQUEST["answer"];
        $data["detail"] = html_entity_decode($_REQUEST["description"]);
        $data["image_url"] = $_REQUEST["imageUrl"];
        $data["count"] = 0;

        D("Faq")->add($data);

        $this->success("添加成功", U("clubfoot/faq"));

    }

    public function faqEdit() {
        $id = $_REQUEST["id"];
        $info = D("Faq")->queryById($id);
        $this->assign("info", $info);
        $this->display("faqedit");
    }

    public function faqEditPost() {

        $id = $_REQUEST["id"];

        $data = D("Faq")->queryById($id);
        $data["name"] = $_REQUEST["name"];
        $data["faq_class_id"] = $_REQUEST["faqClassId"];
        $data["question"] = $_REQUEST["question"];
        $data["answer"] = $_REQUEST["answer"];
        $data["detail"] = html_entity_decode($_REQUEST["description"]);
        $data["image_url"] = $_REQUEST["imageUrl"];

        D("Faq")->updateInfo($data);

        $this->success("更新成功", U("clubfoot/faq"));

    }

    public function faqRemove() {

        $id = $_REQUEST['id'];

        D("Faq")->deleteById($id);

        $this->success('删除成功!', U("clubfoot/faq"));

    }
}